import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import MessageList from '../../components/Wilddog/MessageList'
import { Card } from 'antd';
import pathToRegExp from 'path-to-regexp';

function wilddogMessage({location, dispatch, wilddog }) {
  const {messageList, auth} = wilddog; 
  let messagePath = pathToRegExp('/wilddog/room/:roomId').exec(location.pathname);
  const messageListProps = {
    messageList,
    auth,
    roomId:messagePath[1],
    delOneMessage(item){
      dispatch({
        type:'wilddog/delOneMessage',
        payload:item
      })
    },
    addMessage(item){
      dispatch({
        type:'wilddog/addMessage',
        payload:item
      })
    },
    delMessages(items){
      dispatch({
        type:'wilddog/delMessages',
        payload:items
      })
    },
    updateMessage(item){
    	dispatch({
    		type:'wilddog/updateMessage',
    		payload:item
    	})
    }
  };
  let login = function() {
    dispatch({
      type: 'wilddog/login'
    })
  }
  return (<div className='content-inner'>
     {
     	auth.status? <MessageList {...messageListProps} />: <Card title="点击登录" onClick={login} style={{ width: 300 }}><p >暂未检测到登录状态</p></Card>
     }
    </div>)
}

function mapStateToProps({ wilddog }) {
  return { wilddog }
}
export default connect(mapStateToProps)(wilddogMessage)

wilddogMessage.propTypes = {
  wilddog: PropTypes.object.isRequired
}
